#!/router/bin/perl
use strict;
my $hex_num = 0;
my $sum = 0 ;
my $checksum;
my @packet ;
my $i;
my $hdr_len;
##---------------------------------------------------------
# my @pkt_o = (48 , 0 ) ; 
##my @pkt_o = (0x48,0x6d,0x04,0x0dc, 0xc4,0x2a,0x01,0x4e, 0x19,0x99,0xeb,0x85, 0x72,0xb3,0xe9,0x49,0x62,0xd4 ,0x41,0xe6,0x74,0xca,0xc1,0xf0,0xd2,0xc3 , 0x9d,0x1c,0xcb,0x67,0x75,0xa5,0x99,0x09 ,0x00,0x00,0xe8,0x2a,0xe7,0x75,0x42,0x61 ,0x65,0x30,0x23,0xd8,0x9b,0xa9,0x5c,0x0b ,0x6c,0x23,0x53,0xdb,0x48,0xb2,0x38,0xd3 ,0xda,0xe8,0xb2,0x36,0x7d,0x8b,0x75,0xc6 ,0xa4,0xd0,0x88,0x06,0x01,0xd1,0xa8,0xa6); 
 my @pkt_o = (0x4c, 0xce, 0x04, 0x3f, 0xbb, 0x60, 0x2f, 0x87, 0x23, 0xa8, 0x5e, 0x26, 0x9b, 0x99, 0x9b, 0xd6, 0x39, 0x2e, 0xe0, 0x08, 0xde, 0x61, 0x79, 0xdb, 0x7c, 0x60, 0x43, 0x72, 0x41, 0xb1, 0xca, 0x4f,  0x9b, 0x54, 0xe9, 0x2c, 0x38, 0x56, 0xbc, 0x23, 0x42, 0x5c, 0xdd, 0xa3, 0xab, 0xa2, 0x88, 0xe5);
##---------------------------------------------------------
for($i=0;$i<@pkt_o;$i++){
    @packet[$i] = @pkt_o[$i];
}
$hdr_len = 0x0f & @packet[0];
$hdr_len = $hdr_len * 4 ; 
printf ("Hdr len %d \n", $hdr_len );
print "Sum = $sum \n";
for($i=0;$i<$hdr_len;$i+=2){
    if($i != 10 ) {
        $sum = $sum + ((@packet[$i]<<8) + @packet[$i+1]) ;
        printf("i = %x %x %x %x \n", $i,@packet[$i]<<8, @packet[$i+1],$sum);
    }
    printf ("%x ",$sum);
}
my $carry = ($sum & 0xff0000)>>16 ;
print "c $carry "; 
$sum = $sum & 0x0ffff;
printf ("%x ",$sum);

$sum = $sum +$carry; 
    
printf ("%x ",$sum);

printf ("\nCheck Sum = %x \n",  $sum^0xffff);
